<template>
  <transition name="slide">
    <div class="active-detail">
      <page-header title="活动详情"></page-header>
      <scroll class="detail-content" ref="detailScroll" :class="{'buyShow': buyShow && !picShow}">
        <div>
          <div class="pic">
            <swiper class="pic-swiper" :options="swiperOption" v-if="data.img && data.img.length">
              <swiper-slide class="pic-swiper-item" v-for="(item, index) in data.img" :key="index">
                <img :src="hostPath + '/' + item" alt="">
              </swiper-slide>
              <div class="swiper-pagination" slot="pagination"></div>
            </swiper>
            <ul class="fit">
              <li>年龄：{{data.age}}</li>
              <li>日期：{{data.date}}</li>
              <li>时长：{{data.time}}</li>
            </ul>
          </div>
          <div class="info">
            <p class="title">{{data.title}}</p>
            <p class="des">{{data.des}}</p>
          </div>
          <div class="class-select" v-if="classShow">
            <p class="class-title">套餐</p>
            <swiper class="select-swiper" :options="swiperOption2" v-if="data.class && data.class.length">
              <swiper-slide class="select-swiper-item" v-for="(item, index) in data.class" :key="index">
                <div class="inner" :class="{'active': index === classActive}" @click="classActive = index">
                  <span>{{item.time}}</span>
                  <p>¥{{item.price}}</p>
                </div>
              </swiper-slide>
            </swiper>
          </div>
          <div class="detail">
            <p class="class-title">课程详情</p>
            <!-- 课程安排 -->
            <div class="red-title">课程安排</div>
            <div v-html="data.scheduling" class="detail-item detail-item-text"></div>
            <div class="red-title">用户需知</div>
            <div v-html="data.needKnow" class="detail-item detail-item-text"></div>
          </div>
          <div class="logo-wrapper" v-if="buyShow && !picShow">
            <img src="../../assets/image/logo_2.png" alt="">
            <p>科教链</p>
          </div>
        </div>
      </scroll>
      <ul class="buy" v-if="buyShow && !picShow">
        <li><img src="../../assets/image/icon_home.png" alt=""><span>首页</span></li>
        <li><img src="../../assets/image/icon_share.png" alt=""><span>分享</span></li>
        <li><img src="../../assets/image/icon_ask.png" alt=""><span>咨询</span></li>
        <div class="sign" @click="_sign">立即报名</div>
      </ul>
    </div>
  </transition>
</template>

<script type="text/ecmascript-6">
import PageHeader from 'components/page-header'
import Scroll from 'components/scroll/scroll'
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'
import * as exampleApi from 'api/example'
import { commonOption } from 'api/config'

export default {
  components: {
    PageHeader,
    Scroll,
    swiper,
    swiperSlide
  },
  data () {
    return {
      type: '',
      id: '',
      title: '',
      buyShow: false,
      picShow: false,
      classShow: false,
      classActive: 0,
      data: {},
      swiperOption: {
        direction: 'horizontal',
        pagination: {
          el: '.swiper-pagination',
          bulletClass: 'my-bullet',
          bulletActiveClass: 'my-bullet-active'
        }
      },
      swiperOption2: {
        slidesPerView: 3
        // spaceBetween: 30
      },
      hostPath: commonOption.host
    }
  },
  created() {
    this.type = this.$route.name
    this.id = this.$route.params.id
    // console.log(this.type)
    if (this.type === 'activity') {
      this.buyShow = true
      this.classShow = true
    } else if (this.type === 'camp') {
      this.buyShow = true
      this.picShow = true
      this.classShow = true
    }
  },
  mounted() {
    this._initData()
  },
  methods: {
    _initData() {
      // 发送请求
      let id = this.id
      exampleApi.modePost('/busine/activity/detail', {
        id: id
      }).then(res => {
        if (res.data.data) {
          let activity = res.data.data
          exampleApi.modePost('/weixin/activitiyPrice', {
            activitiyid: id
          }).then(priceRes => {
            if (priceRes.data.data) {
              let priceList = []
              priceRes.data.data.forEach(item => {
                priceList.push({
                  id: item.id,
                  price: item.money,
                  time: item.name
                })
              })
              // mock 数据
              let response = {
                id: activity.id,
                title: activity.name,
                des: activity.intro,
                age: activity.age,
                date: activity.days,
                time: activity.time,
                img: activity.cover.split('@'),
                scheduling: activity.scheduling,
                needKnow: activity.speaker,
                class: priceList
              }
              this.data = response
              this.$refs.detailScroll.refresh()
            }
          })
        }
      })
    },
    _sign() {
      let data = {
        class: this.data.class[this.classActive],
        id: this.data.id
      }
      this.$router.push({
        path: `/personal/activity/signup/${data.id}/${data.class.id}`
      })
    }
  }
}
</script>

<style lang="less">
.slide-enter-active,.slider-leave-active {
  transition: all 0.3s
}
.slide-enter,.slide-leave-to {
  transform: translate3d(100%, 0, 0)
}
.active-detail {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right:0;
  background-color: #e6e6e6;
  z-index: 992;
  .detail-content{
    height:calc(~"100% - 84px");
    overflow: hidden;
    .pic{
      position: relative;
      width: 100%;
      height: 340px;
      // overflow: hidden;
      .pic-swiper{
        z-index: 8;
        .swiper-pagination{
          bottom: 60px;
          width: 100%;
          justify-content: center;
          display: flex;
          .my-bullet{
            margin:  0 5px;
            width: 10px;
            height: 10px;
            display: inline-block;
            border-radius: 100%;
            background-color: rgba(255, 255, 255, 0.7);
          }
          .my-bullet-active{
            background: #fff;
            opacity: 1;
          }
        }
        .pic-swiper-item{
          width: 100%;
          height: 340px;
        }
      }
      img{
        width: 100%;
        height: auto;
      }
      .fit{
        position: absolute;
        bottom: 0;
        left: 0;
        z-index: 10;
        width: 100%;
        height: 49px;
        background-color: rgba(0, 0, 0, 0.4);
        display: flex;
        padding-left: 24px;
        overflow: hidden;
        align-items: center;
        li{
          margin-right: 40px;
          font-size: 20px;
          color: #ffffff;
        }
      }
    }
    .info{
      height: 172px;
      padding: 26px;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      overflow: hidden;
      background-color: #fff;
      .title{
        font-size: 32px;
        color: #333333;
        font-weight: bold;
      }
      .des{
        font-size: 22px;
        line-height: 34px;
        color: #999999;
      }
    }
    .class-title{
      width: calc(~"100% - 22px");
      box-sizing: border-box;
      height: 70px;
      line-height: 70px;
      font-size: 28px;
      color: #264d9f;
      &::before {
        content: '';
        display: inline-block;
        vertical-align: text-bottom;
        width: 18px;
        height: 27px;
        background: url('../../assets/image/tip.png') no-repeat center / 100%;
        margin-right: 12px;
      }
    }
    .class-select{
      padding: 19px;
      margin-top: 20px;
      background-color: #fff;
      .select-swiper{
        width: 100%;
        height: 127px;
        .select-swiper-item{
          display: flex;
          align-items: center;
        }
        .inner{
          // display: inline-block;
          width: 175px;
          height: 115px;
          border-radius: 8px;
          border: solid 1px #cccccc;
          // margin-right: 30px;
          display: flex;
          flex-direction: column;
          text-align: center;
          justify-content: center;
	        color: #666666;
          p{
            margin-top: 20px;
            font-size: 30px;
          }
          span{
            font-size: 22px;
          }
          // &:nth-last-child(1) {
          //   margin-right: 0px;
          // }
        }
        .inner.active{
          width: 186px;
	        height: 127px;
          background-image: linear-gradient(137deg, #3c80ee 0%, #3c6add 100%);
          box-shadow: 0px 0px 13px 0px
            rgba(31, 45, 130, 0.5);
          color: #ffffff;
        }
      }
    }
    .detail{
      padding: 0 19px;
      display: flex;
      flex-direction: column;
      align-items: left;
      background-color: #fff;
      margin-top: 20px;
      .class-title{
        border-bottom: 2px dashed #cccccc;
      }
      .red-title{
        margin-top: 32px;
        width: 100%;
        font-size: 24px;
        color: #f72d62;
        height: 44px;
        line-height: 44px;
        text-align: center;
        background: url('../../assets/image/title_bg.png') no-repeat center / auto 44px;
      }
      .detail-item{
        padding: 40px 0;
        position: relative;
        &::after {
          position: absolute;
          bottom: 0;
          left: 0;;
          content: '';
          display: block;
          width: 100%;
          height: 17px;
          background: url('../../assets/image/line.png') no-repeat center / 100% 17px;
        }

        .detail-item-title{
          font-size: 24px;
          color: #264d9f;
          font-weight: bold;
          &::before {
            content: '';
            display: inline-block;
            // vertical-align: text-bottom;
            width: 15px;
            height: 15px;
            border: 3px solid #264d9f;
            box-sizing: border-box;
            border-radius: 50%;
            margin-right: 11px;
          }
        }
        .detail-item-text{
          font-size: 24px;
          line-height: 49px;
          color: #999999;
        }
        .photos{
          margin-top: 10px;
          .detail-photos-item{
            width:100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            div{
              width: 100%;
              height: 335px;
              background-image: linear-gradient(0deg,
                #00c6fb 0%,
                #0091f3 50%,
                #005bea 100%);
              border-radius: 8px;
              overflow: hidden;
              img{
                width: 100%;
                height: auto;
              }
            }
            span{
              height: 35px;
              background-color: #f2a91d;
              font-size: 20px;
              line-height: 35px;
              color: #ffffff;
              padding: 0 24px;
              text-align: center;
              margin: 14px 0;
            }
          }
        }
      }
      .detail-item.needKnow {
        &:nth-last-child(1)::after{
          display: none;
        }
      }

    }
    .logo-wrapper{
      width: 100%;
      height: 164px;
      background-color: #e5e5e5;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      p{
        font-size: 20px;
        color: #cccccc;
        margin-top: 15px;
      }
      img{
        width: 43px;
        height: 43px;
      }
    }

  }
  .detail-content.buyShow{
    height:calc(~"100% - 164px");
  }
  .buy{
    width: 100%;
    height: 80px;
    background-color: #fff;
    display: flex;
    .sign{
      width: 342px;
      flex: 0 0 342px;
      background-color: #ee4941;
      font-size: 28px;
      line-height: 80px;
      color: #ffffff;
      text-align: center;
    }
    li{
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      border-top: 1px solid#cccccc;
      border-left: 1px solid#cccccc;
      &:nth-child(1) {
        border-left: none;
      }
      span{
        margin-top: 8px;
        font-size: 20px;
        color: #999;
      }
      img{
        width: 26px;
        height: 26px;
      }
    }
  }
}
</style>
